package com.funtl.screw.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.funtl.screw.admin.api.feign.RemoteTokenService;
import com.funtl.screw.common.core.constant.SecurityConstants;
import com.funtl.screw.common.core.util.ResponseResult;
import com.funtl.screw.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author Lusifer
 * @since 2018/9/4 getTokenPage 管理
 */
@RestController
@AllArgsConstructor
@RequestMapping("/online")
@Api(value = "token", tags = "令牌管理模块")
public class SysTokenController {

    private final RemoteTokenService remoteTokenService;

    /**
     * 分页token 信息
     *
     * @param params 参数集
     * @return token集合
     */
    @GetMapping("/page")
    public ResponseResult<Page> getTokenPage(@RequestParam Map<String, Object> params) {
        // 获取请求的
        return remoteTokenService.getTokenPage(params, SecurityConstants.FROM_IN);
    }

    /**
     * 删除
     *
     * @param token getTokenPage
     * @return success/false
     */
    @SysLog("删除用户token")
    @DeleteMapping("/{token}")
    @PreAuthorize("@pms.hasPermission('sys_token_del')")
    public ResponseResult<Boolean> removeById(@PathVariable String token) {
        return remoteTokenService.removeTokenById(token, SecurityConstants.FROM_IN);
    }

}
